package com.servlet;

import com.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

@WebServlet("/ServletLogin")
public class ServletLogin extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String psw = request.getParameter("psw");
        StudentService studentService = new StudentService();
        Boolean login = studentService.login(username, psw);
        if (login){
            request.getSession().setAttribute("username",username);
            response.sendRedirect("entry.jsp");
        }else{
            response.getWriter().write("登陆失败");
            response.setHeader("Refresh","2;URL=index.jsp");
        }
    }
}
